package day01.map集合;

import java.util.*;

/**
 * @author feng
 * @Date 2021/10/17 16:40
 * 存放键值对
 * hsahMap 无序、唯一
 */
public class MapTest {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap();
        map.put("lili", 12132);
        map.put("mingming", 454);
        map.put("zhouzhou", 4242);
        //查看集合中所有的key元素
        /*Set<String> set = map.keySet();
        for (String s:set) {
            System.out.println(s);
        }*/
        // 查看集合中所有的values
        Collection<Integer> c = map.values();
        for (Integer i : c) {
            System.out.println(i);
        }
        // 通过key获取到value
        Set<String> set = map.keySet();
        for (String s : set) {
            System.out.println(map.get(s));
        }

        // 获取键值对
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> e : entries) {
            System.out.println(e.getKey() + "--" + e.getValue());
        }


    }
}
